package com.example.administrator.yuejian2.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.yuejian2.R;
import com.example.administrator.yuejian2.activity.Club_DetailActivity;
import com.example.administrator.yuejian2.bean.MyAttentionClubBean;
import com.example.administrator.yuejian2.viewholder.MyAttentionClubViewHolder;
import com.squareup.picasso.Picasso;

import java.util.List;

import static com.example.administrator.yuejian2.other.Url.IMAGEURL;

public class MyAttentionClubAdapter extends RecyclerView.Adapter{

    private Context context;
    private List<MyAttentionClubBean> list;
    private LayoutInflater layoutInflater;
    public MyAttentionClubAdapter(Context context)
    {
        this.context=context;
        layoutInflater=LayoutInflater.from(context);
    }
    public void getMyAttentionClubList(List<MyAttentionClubBean> list)
    {
        this.list=list;
        notifyDataSetChanged();
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v=LayoutInflater.from(parent.getContext()).inflate(R.layout.my_attention_club_item,parent,false);
        return new MyAttentionClubViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        MyAttentionClubViewHolder viewHolder=(MyAttentionClubViewHolder)holder;
        final MyAttentionClubBean bean=list.get(position);
        Picasso.with(context)
                .load(IMAGEURL+bean.getClub_pic())
                .placeholder(R.mipmap.loading)
                .into(viewHolder.myAttentionClubPic);

        viewHolder.myAttentionClubName.setText(bean.getClub_name());
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context, Club_DetailActivity.class);
                intent.putExtra("c_uid",bean.getClub_id());
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        if (list==null)
        {
            return 0;
        }
        else
        {
            return  list.size();
        }
    }
}
